<?php 

$key = current(array_keys($_POST));

switch ($key) {
	case 'username':
		checkUsername();
		break;
	case 'email':
		checkEamil();
		break;
	case 'password':
		checkPassword();
		break;
}


function checkUsername()
{
	$username = $_POST['username'];
	$preg = "/^[A-z0-9]{6,8}$/";
	$c = preg_match($preg, $username);
	if(!$c){
		$arr = array(
		'error'=>1,
		'info'=>"用户名不符合要求，由6-8位的字母或数字组成"
		);
		echo json_encode($arr);exit;
	}
	$userlist = file_get_contents('./Db/user.txt');

	$userlist = json_decode($userlist,true);

	foreach ($userlist as  $row) {
		if($row['username']==$username){
			$arr = array(
			'error'=>1,
			'info'=>"用户名已存在"
			);
			echo json_encode($arr);exit;
		}
	}
	$arr = array(
		'error'=>0,
		'info'=>"符合条件"
		);
	echo json_encode($arr);exit;

}


function checkEamil(){
	$arr = array(
		'error'=>0,
		'info'=>"符合条件"
		);
	echo json_encode($arr);exit;
}

function checkPassword(){
	$arr = array(
		'error'=>0,
		'info'=>"符合条件"
		);
	echo json_encode($arr);exit;
}












 ?>